package com.vinci.wishDemo.controller;


import com.vinci.util.Constants;
import com.vinci.util.JsonObject;
import com.vinci.wishDemo.entity.TbContentAppreciate;
import com.vinci.wishDemo.service.TbContentAppreciateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

    /**
     * <p>
     * 赞赏表 前端控制器
     * </p>
     *
     * @author 郭三木
     * @since 2021-12-10
     */
@RestController
@RequestMapping("/wishDemo")
@Slf4j
public class TbContentAppreciateController {
    @Resource
    TbContentAppreciateService appreciateService;

    /*
    查询赞赏列表
     */
    @PostMapping("/appreciateList")
    public JsonObject queryappreciateList(String createBy, String beginTime, String endTime) {
        //创建人、开始时间、结束时间
        List<TbContentAppreciate> list = appreciateService.queryappreciateList(createBy, beginTime, endTime);
        JsonObject object = new JsonObject();
        object.setCode(Constants.OK_COOE);
        object.setMsg("ok");
        object.setCount(list.size());
        object.setData(list);
        return object;
    }

    /*
    下架赞赏
     */
    @PostMapping("/delappre")
    public JsonObject delappre(String appreciateId, Model model) {
        JsonObject object = new JsonObject();
        if (appreciateId == null){
            object.setCode(Constants.FAIL_COOE);
            object.setMsg("不能为空");
            return object;
        }
        //修改状态
        appreciateService.delappre(appreciateId);
        //获取当前状态返回给前台
        TbContentAppreciate appstats = appreciateService.querystats(appreciateId);
        model.addAttribute("appstats",appstats);
        object.setCode(Constants.OK_COOE);
        object.setMsg("ok");
        return object;
    }
}

